.class Lcom/baidu/p;
.super Ljava/lang/Thread;


# instance fields
.field final synthetic a:Lcom/baidu/o;

.field private b:Landroid/content/Context;

.field private c:Lcom/baidu/s;

.field private d:Ljava/lang/String;

.field private e:I


# direct methods
.method public constructor <init>(Lcom/baidu/o;Landroid/content/Context;Ljava/lang/String;Lcom/baidu/s;)V
    .locals 0

    iput-object p1, p0, Lcom/baidu/p;->a:Lcom/baidu/o;

    invoke-direct {p0}, Ljava/lang/Thread;-><init>()V

    iput-object p2, p0, Lcom/baidu/p;->b:Landroid/content/Context;

    iput-object p4, p0, Lcom/baidu/p;->c:Lcom/baidu/s;

    iput-object p3, p0, Lcom/baidu/p;->d:Ljava/lang/String;

    return-void
.end method

.method private a()V
    .locals 23

    :try_start_0
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->b:Landroid/content/Context;

    move-object v4, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->a:Lcom/baidu/o;

    move-object v5, v0

    invoke-static {v5}, Lcom/baidu/o;->a(Lcom/baidu/o;)Lcom/baidu/t;

    move-result-object v5

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->d:Ljava/lang/String;

    move-object v6, v0

    invoke-static {}, Lcom/baidu/c;->a()Lcom/baidu/c;

    move-result-object v7

    invoke-virtual {v7}, Lcom/baidu/c;->b()Ljava/lang/String;

    move-result-object v7

    invoke-static {v4, v5, v6, v7}, Lcom/baidu/r;->a(Landroid/content/Context;Lcom/baidu/t;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    new-instance v5, Lorg/json/JSONObject;

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->b:Landroid/content/Context;

    move-object v6, v0

    invoke-static {v6, v4}, Lcom/baidu/w;->d(Landroid/content/Context;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    invoke-direct {v5, v4}, Lorg/json/JSONObject;-><init>(Ljava/lang/String;)V

    const-string v4, "n"

    invoke-virtual {v5, v4}, Lorg/json/JSONObject;->getInt(Ljava/lang/String;)I

    move-result v6

    invoke-static {}, Lcom/baidu/c;->a()Lcom/baidu/c;

    move-result-object v4

    const/4 v7, -0x1

    if-ne v6, v7, :cond_3

    const/4 v7, 0x1

    :goto_0
    invoke-virtual {v4, v7}, Lcom/baidu/c;->a(Z)V

    invoke-static {}, Lcom/baidu/c;->a()Lcom/baidu/c;

    move-result-object v4

    if-nez v6, :cond_4

    const/4 v7, 0x1

    :goto_1
    invoke-virtual {v4, v7}, Lcom/baidu/c;->b(Z)V

    if-lez v6, :cond_5

    invoke-static {}, Lcom/baidu/c;->a()Lcom/baidu/c;

    move-result-object v4

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->a:Lcom/baidu/o;

    move-object v7, v0

    invoke-static {v7}, Lcom/baidu/o;->a(Lcom/baidu/o;)Lcom/baidu/t;

    move-result-object v7

    invoke-virtual {v4, v7}, Lcom/baidu/c;->b(Lcom/baidu/t;)V

    :cond_0
    :goto_2
    const-string v4, "ad"

    invoke-virtual {v5, v4}, Lorg/json/JSONObject;->getJSONArray(Ljava/lang/String;)Lorg/json/JSONArray;

    move-result-object v5

    const/4 v4, 0x0

    move v7, v4

    :goto_3
    if-ge v7, v6, :cond_8

    const-string v4, ""
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    :try_start_1
    invoke-virtual {v5, v7}, Lorg/json/JSONArray;->getJSONObject(I)Lorg/json/JSONObject;

    move-result-object v8

    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v9

    const-string v11, "w_picurl"

    invoke-virtual {v8, v11}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v11

    invoke-static {v11}, Lcom/baidu/w;->e(Ljava/lang/String;)Ljava/lang/String;
    :try_end_1
    .catch Lorg/json/JSONException; {:try_start_1 .. :try_end_1} :catch_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_2

    move-result-object v11

    :try_start_2
    const-string v4, "w_picurl"

    invoke-virtual {v8, v4}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/String;->trim()Ljava/lang/String;

    move-result-object v4

    const-string v12, ""

    invoke-virtual {v4, v12}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v4

    if-nez v4, :cond_1

    const/4 v4, 0x0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->b:Landroid/content/Context;

    move-object v12, v0

    invoke-static {v4, v12, v11}, Lcom/baidu/w;->c(ZLandroid/content/Context;Ljava/lang/String;)Z

    move-result v4

    if-nez v4, :cond_1

    const/4 v4, 0x0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->b:Landroid/content/Context;

    move-object v12, v0

    new-instance v13, Ljava/net/URL;

    const-string v14, "w_picurl"

    invoke-virtual {v8, v14}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v14

    invoke-direct {v13, v14}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    invoke-static {v4, v12, v13, v11}, Lcom/baidu/w;->b(ZLandroid/content/Context;Ljava/net/URL;Ljava/lang/String;)Z

    :cond_1
    invoke-static {}, Lcom/baidu/k;->a()[Lcom/baidu/k;

    move-result-object v12

    array-length v13, v12

    const/4 v4, 0x0

    move v14, v4

    :goto_4
    if-ge v14, v13, :cond_6

    aget-object v15, v12, v14

    sget-object v4, Lcom/baidu/c;->a:Ljava/util/Map;

    invoke-interface {v4, v15}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Ljava/lang/String;

    invoke-static {v4}, Lcom/baidu/c;->a(Ljava/lang/String;)Ljava/net/URL;

    move-result-object v4

    if-nez v4, :cond_2

    const/16 v16, 0x0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->b:Landroid/content/Context;

    move-object/from16 v17, v0

    sget-object v4, Lcom/baidu/c;->a:Ljava/util/Map;

    invoke-interface {v4, v15}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Ljava/lang/String;

    move/from16 v0, v16

    move-object/from16 v1, v17

    move-object v2, v4

    invoke-static {v0, v1, v2}, Lcom/baidu/w;->c(ZLandroid/content/Context;Ljava/lang/String;)Z

    move-result v4

    if-nez v4, :cond_2

    const/16 v16, 0x0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->b:Landroid/content/Context;

    move-object/from16 v17, v0

    new-instance v18, Ljava/net/URL;

    const-string v4, "%s/%s"

    const/16 v19, 0x2

    move/from16 v0, v19

    new-array v0, v0, [Ljava/lang/Object;

    move-object/from16 v19, v0

    const/16 v20, 0x0

    invoke-static {}, Lcom/baidu/c;->a()Lcom/baidu/c;

    move-result-object v21

    invoke-virtual/range {v21 .. v21}, Lcom/baidu/c;->g()Ljava/lang/String;

    move-result-object v21

    aput-object v21, v19, v20

    const/16 v20, 0x1

    sget-object v21, Lcom/baidu/c;->a:Ljava/util/Map;

    move-object/from16 v0, v21

    move-object v1, v15

    invoke-interface {v0, v1}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v21

    aput-object v21, v19, v20

    move-object v0, v4

    move-object/from16 v1, v19

    invoke-static {v0, v1}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v4

    move-object/from16 v0, v18

    move-object v1, v4

    invoke-direct {v0, v1}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    sget-object v4, Lcom/baidu/c;->a:Ljava/util/Map;

    invoke-interface {v4, v15}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Ljava/lang/String;

    move/from16 v0, v16

    move-object/from16 v1, v17

    move-object/from16 v2, v18

    move-object v3, v4

    invoke-static {v0, v1, v2, v3}, Lcom/baidu/w;->b(ZLandroid/content/Context;Ljava/net/URL;Ljava/lang/String;)Z
    :try_end_2
    .catch Lorg/json/JSONException; {:try_start_2 .. :try_end_2} :catch_3
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_2

    :cond_2
    add-int/lit8 v4, v14, 0x1

    move v14, v4

    goto :goto_4

    :cond_3
    const/4 v7, 0x0

    goto/16 :goto_0

    :cond_4
    const/4 v7, 0x0

    goto/16 :goto_1

    :cond_5
    if-gtz v6, :cond_0

    :try_start_3
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->c:Lcom/baidu/s;

    move-object v4, v0

    const/4 v7, 0x0

    sget-object v8, Lcom/baidu/FailReason;->NO_AD:Lcom/baidu/FailReason;

    invoke-interface {v4, v7, v8}, Lcom/baidu/s;->a(Ljava/lang/Exception;Lcom/baidu/FailReason;)V
    :try_end_3
    .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_3} :catch_0

    goto/16 :goto_2

    :catch_0
    move-exception v4

    const-string v5, "updateCacheAds"

    invoke-static {v5, v4}, Lcom/baidu/bk;->a(Ljava/lang/String;Ljava/lang/Throwable;)I

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->c:Lcom/baidu/s;

    move-object v5, v0

    sget-object v6, Lcom/baidu/FailReason;->OTHER_EXCEPTION:Lcom/baidu/FailReason;

    invoke-interface {v5, v4, v6}, Lcom/baidu/s;->a(Ljava/lang/Exception;Lcom/baidu/FailReason;)V

    :goto_5
    return-void

    :cond_6
    :try_start_4
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->b:Landroid/content/Context;

    move-object v4, v0

    invoke-static {v4, v8, v11}, Lcom/baidu/Ad;->a(Landroid/content/Context;Lorg/json/JSONObject;Ljava/lang/String;)Lcom/baidu/Ad;

    invoke-static {}, Lcom/baidu/c;->a()Lcom/baidu/c;

    move-result-object v4

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->a:Lcom/baidu/o;

    move-object v12, v0

    invoke-static {v12}, Lcom/baidu/o;->a(Lcom/baidu/o;)Lcom/baidu/t;

    move-result-object v12

    invoke-virtual {v4, v12, v9, v10, v8}, Lcom/baidu/c;->a(Lcom/baidu/t;JLorg/json/JSONObject;)V

    move-object/from16 v0, p0

    iget v0, v0, Lcom/baidu/p;->e:I

    move v4, v0

    add-int/lit8 v4, v4, 0x1

    move v0, v4

    move-object/from16 v1, p0

    iput v0, v1, Lcom/baidu/p;->e:I
    :try_end_4
    .catch Lorg/json/JSONException; {:try_start_4 .. :try_end_4} :catch_3
    .catch Ljava/lang/Exception; {:try_start_4 .. :try_end_4} :catch_2

    :cond_7
    :goto_6
    add-int/lit8 v4, v7, 0x1

    move v7, v4

    goto/16 :goto_3

    :catch_1
    move-exception v8

    move-object/from16 v22, v8

    move-object v8, v4

    move-object/from16 v4, v22

    :goto_7
    :try_start_5
    const-string v9, "updateCacheAds"

    invoke-static {v9, v4}, Lcom/baidu/bk;->a(Ljava/lang/String;Ljava/lang/Throwable;)I

    const-string v4, ""

    invoke-virtual {v8, v4}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v4

    if-nez v4, :cond_7

    const/4 v4, 0x0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->b:Landroid/content/Context;

    move-object v9, v0

    invoke-static {v4, v9, v8}, Lcom/baidu/w;->b(ZLandroid/content/Context;Ljava/lang/String;)Z

    goto :goto_6

    :catch_2
    move-exception v4

    const-string v8, "updateCacheAds"

    invoke-static {v8, v4}, Lcom/baidu/bk;->a(Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_6

    :cond_8
    move-object/from16 v0, p0

    iget v0, v0, Lcom/baidu/p;->e:I

    move v4, v0

    if-lez v4, :cond_9

    const-string v4, "updateCacheAds"

    const-string v5, "updated (%d/%d)"

    const/4 v6, 0x2

    new-array v6, v6, [Ljava/lang/Object;

    const/4 v7, 0x0

    move-object/from16 v0, p0

    iget v0, v0, Lcom/baidu/p;->e:I

    move v8, v0

    invoke-static {v8}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v8

    aput-object v8, v6, v7

    const/4 v7, 0x1

    invoke-static {}, Lcom/baidu/c;->a()Lcom/baidu/c;

    move-result-object v8

    invoke-virtual {v8}, Lcom/baidu/c;->p()I

    move-result v8

    invoke-static {v8}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v8

    aput-object v8, v6, v7

    invoke-static {v5, v6}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v5

    invoke-static {v4, v5}, Lcom/baidu/bk;->b(Ljava/lang/String;Ljava/lang/String;)I

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->a:Lcom/baidu/o;

    move-object v4, v0

    const/4 v5, 0x1

    invoke-static {v4, v5}, Lcom/baidu/o;->a(Lcom/baidu/o;Z)V

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->c:Lcom/baidu/s;

    move-object v4, v0

    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/baidu/p;->a:Lcom/baidu/o;

    move-object v5, v0

    invoke-static {v5}, Lcom/baidu/o;->b(Lcom/baidu/o;)Z

    move-result v5

    invoke-interface {v4, v5}, Lcom/baidu/s;->a(Z)V

    :cond_9
    invoke-static {}, Lcom/baidu/c;->a()Lcom/baidu/c;

    move-result-object v4

    invoke-virtual {v4}, Lcom/baidu/c;->d()V
    :try_end_5
    .catch Ljava/lang/Exception; {:try_start_5 .. :try_end_5} :catch_0

    goto/16 :goto_5

    :catch_3
    move-exception v4

    move-object v8, v11

    goto :goto_7
.end method


# virtual methods
.method public run()V
    .locals 2

    const-string v0, "AdRequestHandler.run"

    iget-object v1, p0, Lcom/baidu/p;->a:Lcom/baidu/o;

    invoke-static {v1}, Lcom/baidu/o;->a(Lcom/baidu/o;)Lcom/baidu/t;

    move-result-object v1

    invoke-virtual {v1}, Lcom/baidu/t;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v0, v1}, Lcom/baidu/bk;->b(Ljava/lang/String;Ljava/lang/String;)I

    :try_start_0
    iget-object v0, p0, Lcom/baidu/p;->c:Lcom/baidu/s;

    invoke-interface {v0}, Lcom/baidu/s;->a()V

    invoke-direct {p0}, Lcom/baidu/p;->a()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    :goto_0
    return-void

    :catch_0
    move-exception v0

    invoke-static {v0}, Lcom/baidu/bk;->a(Ljava/lang/Throwable;)I

    goto :goto_0
.end method
